<?php

class NewModule extends MySQLCN {

    function Add() {
        $qry = "INSERT INTO `menu` 
            ( `title`, `path`, `parent`, `rank`) 
            VALUES 
            ( '{$_POST['title']}', '{$_POST['path']}','{$_POST['parent']}', '{$_POST['rank']}')";
        return $this->insert($qry);
    }
	
    function AddLink() {
        $qry = "INSERT INTO `link` 
            ( `mid`, `user_id`, `level_id`, `dummy`) 
            VALUES 
            ( '{$_GET['mid1']}', '{$_GET['uid']}','{$_POST['level_id']}', '1')";
        return $this->insert($qry);
    }
	
	function UpdateLink() {
    $qry = "UPDATE `link` SET
              `level_id` = '{$_POST['level_id']}'
               WHERE user_id = '{$_GET['uid']}' and mid='{$_GET['mid1']}'";
        return $this->insert($qry);
    }
	
    function Update() {
        	
	$qryslct = "SELECT * FROM `menu` WHERE rank = '{$_POST['rank']}' AND parent = '{$_POST['parent']}'";
    $resultqryslct = $this->select($qryslct);
	$md=$resultqryslct[0]['mid'];
	$pr=$resultqryslct[0]['parent'];
		
	$qry1 = "UPDATE `menu` SET `rank` = '{$_POST['hrank']}' WHERE mid = '{$md}' AND parent='{$pr}'";
	$this->insert($qry1);
		
    $qry = "UPDATE `menu` SET
              `title` = '{$_POST['title']}', 
              `path` = '{$_POST['path']}', 
              `parent` = '{$_POST['parent']}',
              `rank` = '{$_POST['rank']}', 
              `dummy` = '1' 
               WHERE mid = '{$_POST['menuid']}' and parent='{$_POST['hparent']}'";
        return $this->insert($qry);
    }

    function Delete($mid) {
        $qry = "DELETE FROM `menu` WHERE mid = '$mid'";
        return $this->insert($qry);
    }

    function get($EmpID) {
        $qry = "SELECT * 
                FROM `menu` WHERE mid = '{$EmpID}'";
        return $this->select($qry);
    }
    
    function AllList() {
        $qry = "SELECT * FROM `menu` where parent=0 order by rank";
        return $this->select($qry);
    }
	
	function AllList1($mID) {
        $qry = "SELECT * 
                FROM `menu` WHERE parent = '{$mID}' order by rank";
        return $this->select($qry);
    }
    function AllList2($mID) {
        $qry = "SELECT * 
                FROM `menu` WHERE parent = '{$mID}'";
        return $this->select($qry);
    }
	
	function getlink($uID,$mID) {
        $qry = "SELECT * FROM `link` WHERE user_id = '{$uID}' AND mid = '{$mID}'";
        return $this->select($qry);
    }
}

?>